<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="组装拆卸单打印">

    <style media="print">
        @page {
            margin: 0mm; /* this affects the margin in the printer settings */
            size: landscape;
        }
    </style>

    <style>
        table{border-collapse: collapse;width: 100%}
        table td, table th{border: 1px solid #000000;}
        table td{padding:4px 0 4px 4px;}
        table td, table th{border: 1px solid #000000;}
        span,div,td,th{font-size:14px;}
    </style>

    <script>
        function genPrintDiv($div, id, title, barCode) {
            let child = "<div id='"+id+"' style='padding: 40px;page-break-after:always;'>\n" +
                "    <div style='width: 100%;height: 100px;line-height: 100px;position: relative;text-align: center;'>\n" +
                "        <span style='font-weight: bold;font-size: 20px;'>"+title+"</span>\n" +
                "        <div style='position: absolute;top: 0px;right: 0px;'>\n" +
                "            <canvas class='barcode' style='width: 200px;height: 100px;'/>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "    <div class='before' style='padding-top: 20px;'></div>\n" +
                "    <div style='padding: 20px 10px 10px 0;'><span style='font-weight: bold;'>原商品清单</span></div>\n" +
                "    <div class='table_old'></div>\n" +
                "    <div style='padding: 20px 10px 10px 0;'><span style='font-weight: bold;'>新商品清单</span> </div>\n" +
                "    <div class='table_new'></div>\n" +
                "    <div class='end' style='padding-top: 20px;'></div>\n" +
                "</div>";
            $div.append(child);

            if (barCode != undefined) {
                $('#'+id+' .barcode').JsBarcode(barCode);
            }
        }

        function printPage(data){
            let $printDiv = $("#printDiv");
            $printDiv.empty();

            genPage(data,$printDiv);

            setTimeout(function () {
                window.print();
            },100);
        }

        function genPage(data,$printDiv){
            let totalAmt = 0;
            $.each(data.saleGoodsVoList, function (i,d) {
                totalAmt += parseFloat(d.amount);
            });


            genPrintDiv($printDiv, data.id, "组装拆卸单", data.no);
            let beforeList = [];
            beforeList.push({width:0,label:"经办人", content:data.user.name});
            beforeList.push({width:0, label: "业务日期", content: GMTToDate(data.date)});
            beforeList.push({width:0, label:"出库仓库", content:data.oldHouseVo.store.name+">"+data.oldHouseVo.name});
            beforeList.push({width:0, label:"入库仓库", content:data.newHouseVo.store.name+">"+data.newHouseVo.name});
            genPrintLine($('#'+data.id+' .before'), beforeList);

            let endList = [];
            endList.push({width:0, newLine: true,label:"备注", content:genString(data.remark)});
            endList.push({label:"制单人", content:data.makeUser.name});
            endList.push({width:0, label:"制单时间", content:data.makeTime});
            genPrintLine($('#'+data.id+' .end'), endList);

            let list=[];
            $.each(data.joinSplitOldGoodsVoList, function (i,vo) {
                let data={};
                data.index = (i+1);
                data.no = vo.goodsVo.no;
                data.name = vo.goodsVo.name;
                data.norms = genGoodsNorm(vo.norms);
                data.unit = genUnitName(vo.goodsVo.goodsUnitVoList, vo.unitId);
                data.price = getPrice(vo.price);
                data.number = vo.number;
                data.amount = getPrice(vo.amount);
                list.push(data);
            });

            genPrintTable($('#'+data.id+' .table_old'), ['序号','商品编号','商品名称','规格','单位','单价','数量','金额'],list);

            list=[];
            $.each(data.joinSplitNewGoodsVoList, function (i,vo) {
                let data={};
                data.index = (i+1);
                data.no = vo.goodsVo.no;
                data.name = vo.goodsVo.name;
                data.norms = genGoodsNorm(vo.norms);
                data.unit = genUnitName(vo.goodsVo.goodsUnitVoList, vo.unitId);
                data.price = getPrice(vo.price);
                data.number = vo.number;
                data.amount = getPrice(vo.amount);
                list.push(data);
            });

            genPrintTable($('#'+data.id+' .table_new'), ['序号','商品编号','商品名称','规格','单位','单价','数量','金额'],list);
        }
    </script>

</html:header>
<body>
<div id="printDiv">
</div>
</body>
</html>